from time import sleep

from selenium import webdriver

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

wd = webdriver.Edge("msedgedriver")
wd.implicitly_wait(10)
wd.maximize_window()
wd.get("https://www.bv2008.cn/app/user/register.php?type=org")
# 根据ID查找
element1=wd.find_element(By.ID,"login_name")
# 输入文本
element1.send_keys("小丽")


# 根据CSS
element2=wd.find_element(By.CSS_SELECTOR,"#reg_org > table > tbody:nth-child(1) > tr:nth-child(10) > td:nth-child(2) > input[type=radio]:nth-child(2)")
# 点击
element2.click()



# element3=wd.find_element(By.ID,'district1')
# s=Select(element3)
# s.select_by_value('510')

# 下拉框选择
# Select(wd.find_element(By.ID,'district1')).select_by_value('510')
Select(wd.find_element(By.ID,'district1')).select_by_visible_text('西城区')


# 切换页面
wd.find_element(By.CSS_SELECTOR,'#org_record1 > tr:nth-child(2) > td:nth-child(2) > a').click()
# 切入
# wd.switch_to.frame('iframe_info')
wd.switch_to.frame(wd.find_element(By.CSS_SELECTOR,'body > div.div_tips > iframe'))
wd.find_element(By.CSS_SELECTOR,'#org_list > ul > li > span.son > ul > li:nth-child(1) > a:nth-child(3)').click()
# 回到原页面
wd.switch_to.default_content()


wd.find_element(By.CSS_SELECTOR,'body > div.nav > div > a:nth-child(2)').click()
wd.find_element(By.CSS_SELECTOR,'body > div.nav > div > a:nth-child(2)').click()
wd.find_element(By.CSS_SELECTOR,'body > div.main > div:nth-child(1) > ul > li:nth-child(2) > div > a > img').click()

for window_handle in wd.window_handles:
    wd.switch_to.window(window_handle)
    if '救在身边' in wd.window_handles:
        break

wd.find_element(By.CSS_SELECTOR,'#main_body > div.wrap.clearfix.m10 > div > div.clearfix > div.l.desc_txt > table > tbody > tr:nth-child(2) > td > a:nth-child(4)').click()

sleep(4)
# wd.quit()